/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dsw2.escuela.bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dsw2.escuela.dao.MaestroDaoLocal;
import mx.its.dsw2.escuela.enumeracion.EstadoTransaccion;
import mx.its.dsw2.escuela.modelo.Maestro;

/**
 *
 * @author Maq-8
 */
@Stateless
public class MaestroBl implements MaestroBlLocal {

    @EJB
    private MaestroDaoLocal maestroDao;

    @Override
    public EstadoTransaccion register(Maestro teacher) {
        if (maestroDao.findByDuplicity(teacher)) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            maestroDao.create(teacher);
            return EstadoTransaccion.COMPLETO;
        }
    }

    @Override
    public EstadoTransaccion modify(Maestro teacher) {
        if (teacher.getId() == null || maestroDao.find(teacher.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            maestroDao.edit(teacher);
            return EstadoTransaccion.COMPLETO;
        }
    }

    @Override
    public EstadoTransaccion delete(Maestro teacher) {
        if (teacher.getId() == null || maestroDao.find(teacher.getId()) == null) {
            return EstadoTransaccion.INCOMPLETO;
        } else {
            maestroDao.remove(teacher);
            return EstadoTransaccion.COMPLETO;
        }
    }

    @Override
    public List<Maestro> getAll() {
        return maestroDao.findAll();
    }

    @Override
    public Maestro findById(int idTeacher) {
        return maestroDao.find(idTeacher);
    }
}
